<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<label><input id="year" type="text" value="" name="">年</label>
	<label><input id="month" type="text" value="" name="">月</label>
	<label><input id="day" type="text" value="" name="">日</label>
	<input id="btn" type="button" value="计算" name="">
</body>
<script type="text/javascript">
	var btn=document.getElementById("btn");
	btn.onclick=function(){
		var year=document.getElementById("year");
		var month=document.getElementById("month");
		var day=document.getElementById("day");
		var total=0;
		var total1=31;
		var arr=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		for (var i = 0; i < month.value - 1; i++) {
			total = total + arr[i];
			total1=arr[i+1];
		}
		console.log(total);
		console.log(total1);
		if (( (year.value % 4 == 0 && year.value % 100 != 0) || year.value % 400 == 0 ) && month.value > 2) {
			if (Number(day.value)<=total1) {
				total = Number(total) + Number(day.value) + Number(1);
				document.write("该日期为一年中的第" + total  + "天" );
			} else{
				alert("你输入的天数超过了该月份的天数");
			}
		} else {
			if (Number(day.value)<=total1) {
				total = Number(total) + Number(day.value);
				document.write("该日期为一年中的第" + total  + "天" );
			} else{
				alert("你输入的天数超过了该月份的天数");
			}
		}
	}
</script>
</html>